package com.sk.cardeal.act.home.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.sk.cardeal.R;
import com.sk.cardeal.adapter.TodayAdapter;
import com.sk.cardeal.base.BaseFragment;
import com.sk.cardeal.callback.HandleDataCallBack;
import com.sk.cardeal.entity.ToadyMessageList;
import com.sk.cardeal.entity.TodayMessage;
import com.sk.cardeal.utils.AppApi;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by sk on 2018/1/20.
 */

public class TodayMessageFragment extends BaseFragment implements HandleDataCallBack {
    @BindView(R.id.tv_kind)
    TextView tvKind;
    @BindView(R.id.data_ryc)
    RecyclerView dataRyc;
    Unbinder unbinder;
    private int type;
    private TodayAdapter adapter;


    public static TodayMessageFragment newInstance(int typeId) {
        Bundle args = new Bundle();
        args.putInt("type", typeId);
        TodayMessageFragment fragment = new TodayMessageFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getContentView() {
        return R.layout.fragment_today_data;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        dataRyc.setLayoutManager(new LinearLayoutManager(mContext));

        type = getArguments().getInt("type");
        switch (type) {
            case 0:
                tvKind.setText("入场车辆");
                break;
            case 1:
                tvKind.setText("待维修");
                break;
            case 2:
                tvKind.setText("已完工");
                break;
        }
        AppApi.getTodayListData(type, TodayMessageFragment.this, 0, getActivity());
    }

    @Override
    public void handlerSuccessData(String result, int tag) {
        ToadyMessageList toadyMessageList = JSON.parseObject(result,ToadyMessageList.class);
        List<TodayMessage> todayMessages = toadyMessageList.getResultList();
        adapter = new TodayAdapter(R.layout.item_message_board,todayMessages);
        dataRyc.setAdapter(adapter);
    }

    @Override
    public void handlerFailData(String failString, int tag) {

    }

    @Override
    public void handleErrorData(String error, int tag) {

    }
}
